package com.bckj.fastboot.iot.biz.controller;

import com.bckj.fastboot.core.lang.model.PageResult;
import com.bckj.fastboot.core.page.PageSupport;
import com.bckj.fastboot.iot.api.service.IotProtocolRemoteService;
import com.bckj.fastboot.iot.biz.service.IotProtocolService;
import com.bckj.fastboot.iot.common.dto.query.IotProtocolQuery;
import com.bckj.fastboot.iot.common.dto.request.IotProtocolRequest;
import com.bckj.fastboot.iot.common.dto.response.IotProtocolResponse;
import com.bckj.fastboot.iot.common.entity.IotProtocolItem;
import com.bckj.fastboot.iot.biz.service.IotProtocolQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * IotProtocolController
 *
 * @author wfc
 **/
@RestController
@RequiredArgsConstructor
@RequestMapping("iotProtocol")
public class IotProtocolController implements IotProtocolRemoteService {

    private final IotProtocolService iotProtocolService;
    private final IotProtocolQueryService iotProtocolQueryService;


    @Override
    public boolean save(IotProtocolRequest request) {
        return iotProtocolService.save(request);
    }

    @Override
    public boolean update(IotProtocolRequest request) {
        return iotProtocolService.update(request);
    }

    @Override
    public IotProtocolResponse details(Long id) {
        return iotProtocolQueryService.details(id);
    }

    @Override
    public PageResult<IotProtocolResponse> page(IotProtocolQuery query) {
        return iotProtocolQueryService.page(PageSupport.buildPage(), query);
    }

    @Override
    public void clearItemsCache(String protocolCode, String cmd) {
        String[] cmdArr = StringUtils.hasText(cmd) ?
                cmd.split(",") : null;
        iotProtocolService.clearItemsCache(protocolCode, cmdArr);
    }

    @Override
    public List<IotProtocolItem> findItems(String protocolCode, String cmd) {
        return iotProtocolQueryService.findItems(protocolCode, cmd);
    }
}
